﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A54Path类处理路径字符串
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = @"C:\Users\Administrator\Desktop\编码.txt";
            //获取扩展名
            string ext = Path.GetExtension(path);//.txt
            Console.WriteLine(ext);
          
            //获取文件名 Path.GetFileName
            string fileName = Path.GetFileName(path);
            Console.WriteLine(fileName);
            //获取没有扩展名的文件名 Path.GetFileNameWithoutExtension
            string fileName1 = Path.GetFileNameWithoutExtension(path);
            Console.WriteLine(fileName1);
            //获取完整路径 Path.GetFullPath
            string file = "a.txt";
            Console.WriteLine(Path.GetFullPath(file));

            //拼接路径 Path.Combine
            string dir = Directory.GetCurrentDirectory();
            string fileName2 = "a.txt";
            Console.WriteLine(Path.Combine(dir, fileName2));
        }
    }
}
